﻿@model Dqaqs.Data.DataSource

@{
    ViewBag.Title = "Details";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<h2>Details</h2>

<fieldset>
    <legend>DataSource</legend>

    <div class="display-label">Title</div>
    <div class="display-field">
        @Html.DisplayFor(model => model.Title)
    </div>

    @Html.HiddenFor(model => model.Id, new { id = "dsId" })
    <div class="display-label">ProjectId</div>
    <div class="display-field">
        @Html.DisplayFor(model => model.ProjectId)
    </div>

    <div class="display-label">Schema</div>
    <div class="display-field" id="schemaDiv">
        @Html.DisplayFor(model => model.Schema)
    </div>
</fieldset>
<p>
    @Html.ActionLink("Edit", "Edit", new { id = Model.Id }) |
    @Html.ActionLink("Back to List", "Index")
</p>

<script>
    $(function () {
        var dsId = $("#dsId").val();
        var targetId = "schemaDiv";
        loadSchema(dsId, targetId);
    });
    function loadSchema(dsId, targetId) {
        $.getJSON("/DataSource/GetSchema/" + dsId, function (data) {
            var html = "<ul>"
            $.each(data.Tables, function (i, tbl) {
                html += "<li>" + tbl.Name + "<ul>";
                $.each(tbl.Columns, function (i, col) {
                    html += "<li>" + (col.IsKey == true ? "*" : "") + col.Name + "</li>";
                });
                html += "</ul></li>";
            });
            $("#" + targetId).html(html);
        });
        }
</script>
